package com.salt.modules.notice.hystrix;

import com.salt.modules.notice.entity.NoticeData;
import com.salt.modules.notice.feign.SendNoticeClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @Description 区域（消息推送中心）远程调用失败处理类
 * @Author salt
 * @Date 2021/11/4
 * @Version 1.0.1
 */
@Slf4j
@Component
public class SendNoticeClientHystrix implements FallbackFactory<SendNoticeClient> {
    @Override
    public SendNoticeClient create(Throwable throwable) {
        String message = throwable.getMessage() == null ?
                "No available server for client: SALT-NOTICE" :
                throwable.getMessage();
        log.info("Hystrix:{}", message);
        return new SendNoticeClient() {
            @Override
            public void pc(NoticeData data, Set<String> userIds) {
                log.info("PC端消息发送异常");
            }

            @Override
            public void pc(NoticeData data) {
                log.info("PC端消息发送异常");
            }

            @Override
            public void pcBatch(String notices) {
                log.info("PC端消息批量发送异常");
            }

            @Override
            public void app(NoticeData data, Set<String> userIds) {
                log.info("APP端消息发送异常");
            }

            @Override
            public void pcapp(NoticeData data, Set<String> userIds) {
                log.info("PC、APP端消息同时发送异常");
            }
        };
    }
}
